package com.zx.deploy.common.utils;

import java.io.Serializable;
import java.util.List;

/**
 * 
 * @Description: 分页对象
 * @author jbyu
 * @date 2018年1月27日 下午5:55:25
 * 
 */
public class PagerModel implements Serializable {

	public static final int DEFAULT_PAGE_SIZE = 10;
	/**
	 * 
	 */
	private static final long serialVersionUID = -7253454781786513930L;

	/**
	 * 总记录数
	 */
	private int totalCount;

	/**
	 * 每页显示个数
	 */
	private int pageSize;

	/**
	 * 当前页数
	 */
	private int currentPage;

	/**
	 * 返回数据
	 */
	private List items;

	/**
	 * 总页数
	 */
	private int totalPage;

	public PagerModel() {
		this.currentPage = 1;
		this.pageSize = DEFAULT_PAGE_SIZE;
	}

	public PagerModel(int currentPage, int pageSize) {
		this.currentPage = currentPage <= 0 ? 1 : currentPage;
		this.pageSize = pageSize <= 0 ? DEFAULT_PAGE_SIZE : pageSize;
	}

	// 整数型的构造方法
	public PagerModel(Integer currentPage, Integer pageSize) {
		if (currentPage == null) {
			currentPage = 1;
		}
		if (pageSize == null) {
			pageSize = DEFAULT_PAGE_SIZE;
		}
		this.currentPage = currentPage <= 0 ? 1 : currentPage;
		this.pageSize = pageSize <= 0 ? DEFAULT_PAGE_SIZE : pageSize;
	}

	/**
	 * 设置结果 及总页数
	 * 
	 * @param list
	 */
	public void build(List rows) {
		this.setItems(rows);
		int count = this.getTotalCount();
		int divisor = count / this.getPageSize();
		int remainder = count % this.getPageSize();
		this.setTotalPage(remainder == 0 ? divisor == 0 ? 1 : divisor : divisor + 1);
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public List getItems() {
		return items;
	}

	public void setItems(List items) {
		this.items = items;
	}

}
